/**
 * 使用面向对象的语言实现一个计算器控制台程序，要求输入两个数和运算符，得到结果
 *
 */
import * as readline from "readline";

const rl = readline.createInterface(process.stdin, process.stdout);

class Operation{
    public static GetResult(numberA: number, numberB: number, operate : string): number|null{
        let result = 0;
        switch (operate){
        case "+":
            result = numberA + numberB;
            break;
        case "-":
            result = numberA - numberB;
            break;
        case "*":
            result = numberA * numberB;
            break;
        case "/":
            if(numberB === 0){
                console.log("被除数为0");
                rl.pause();
                return null;

            }
            result = numberA / numberB;
            break;
        }

        return result;
    }
}

let numberA = 0;
let numberB = 0;
let operate = "";
rl.question("请输入数字A\n", input => {
    numberA = Number(input);

    rl.question("请选择运算符（+、-、*、/）\n", input => {
        operate = input;

        rl.question("请输入数字B\n", input => {
            numberB = Number(input);

            const result = Operation.GetResult(numberA,numberB,operate);
            console.log("结果是：", result);

            rl.pause();
        });
    });
});

